import React, { Component } from 'react';

import { View } from 'remax/wechat';
import { Input, Button } from 'remax/one';

class CustomInput extends Component {
  constructor(props) {
    super(props);
    this.state = {
      value: ''
    }
  }
  handleChange = (e) => {
    this.setState({
      value: e.target.value
    })
  }
  handleSubmit = (e) => {
    if (this.state.value !== '') {
      this.props.addTodo(this.state.value);
      this.setState({
        value: ''
      })
    }
    
  }
  render() {
    return (
      <View>
        <Input type="text" placeholder="please input..." value={this.state.value} onInput={this.handleChange.bind(this)} onConfirm={this.handleSubmit.bind(this)}/>
        <Button onClick={this.handleSubmit}>add</Button>
      </View>
    )
  }
}
export default CustomInput;